﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace AutoCompleteListBuilder
{
    public partial class AutoListBuilder : UserControl
    {
        public Brush BorderColor
        { set; get; }

        public Brush FontColor
        { set; get; }

        public List<LstItm> LookupCollection
        {
            get;
            set;
        }

        public ObservableCollection<LstItm> ListboxCollection
        {
            get;
            set;
        }
        
        public AutoListBuilder()
        {
            InitializeComponent();
            ListboxCollection = new ObservableCollection<LstItm>();
            this._listbox.ItemsSource = ListboxCollection;
        }

        private void _autocompletebox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {            
                if (this._autocompletebox.SelectedItem == null)
                {
                    this._autocompletebox.Text = "";
                }
                else
                {
                    LstItm listitem = this._autocompletebox.SelectedItem as LstItm;
                    this._autocompletebox.Text = listitem.description;
                    ListboxCollection.Add(listitem);
                }
            }
        }
        
        private void DummyRectForDoubleClick_Loaded(object sender, RoutedEventArgs e)
        {
            GraphicsUtils.DoubleClickHandler dblClickHandler = new GraphicsUtils.DoubleClickHandler(ListBoxItem_DoubleClick);
            GraphicsUtils gu = new GraphicsUtils();
            gu.AttachDoubleClick(sender, dblClickHandler);
        }
        
        private void ListBoxItem_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListboxCollection.Remove((this._listbox.SelectedItem as LstItm));
        }
    }
}
